<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function __log($msg,$type='base'){
	$dir = ROOT_PATH . DS .'data' . DS . 'log' . DS . $type . DS . date('Y-m');
	$file = $dir . DS . date('d') . '.txt';
	if(!is_dir($dir) && !mkdir($dir,0777,true)){
		return false;
	}
	if(is_array($msg)){
		$msg = json_encode($msg,JSON_UNESCAPED_UNICODE);
	}
	$content = '['.date('H:i:s').'] ' . $msg . PHP_EOL;
	return file_put_contents($file,$content,FILE_APPEND) > 0;
}

function __iswechat(){
    if(array_key_exists('HTTP_USER_AGENT',$_SERVER)){
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false){
            //nothing
        }else{
            return true;
        }
    }
    return false;
}
function __iswinwechat(){
    if(isset($_SERVER['HTTP_USER_AGENT'])){
        return strpos($_SERVER['HTTP_USER_AGENT'],'WindowsWechat') > 0;
    }
    return false;
}

function ajax($info,$flag=false,$data=''){
	$ret = [
		'flag' => $flag ? true : false,
		'info' => $info,
		'data' => $data,
	];
	echo json_encode($ret,JSON_UNESCAPED_UNICODE);
	exit();
}

//代理获取自己的订单状态
function __order_status($key,$withspan=false){
	$arr = \think\Config::get('nawen.order_status');
	if(array_key_exists($key,$arr)){
		if($withspan){
			return "<span style='color:{$arr[$key][1]}'>{$arr[$key][0]}</span>";
		}else{
			return $arr[$key][0];
		}
	}else{
		return "";
	}
}
//代理端 根据自己的订单状态显示对应操作按钮
function __order_status_btns($status,$indetailpage=false){
	$html = "";
	//<div class="g-btn-edit active g-m-r g-fr" data-action="again">再次购买</div>
	//<div class="g-btn-edit g-m-r g-fr" data-action="delete">删除订单</div>
	if($status == 1){
		$html.="<div class='g-btn-edit active g-m-r g-fr order-status-btn' data-action='zhifu'>立即支付</div>";
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='quxiao'>取消订单</div>";//single
		
	}else if($status == 10){
		//立即支付、查看打款凭证
		if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>打款凭证</div>";
		}
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='zhifu'>立即支付</div>";
	}else if($status == 2){
		//待审核
		if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>打款凭证</div>";
		}
		//$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='chedan'>申请撤单</div>";
	}else if($status == 3){
		if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>打款凭证</div>";
		}
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='chedan'>申请撤单</div>";
	}else if($status == 7){
		if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>打款凭证</div>";
		}
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='chedan'>申请撤单</div>";
	}else if($status == 4){
		//if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='wuliu'>物流信息</div>";
		//}
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>打款凭证</div>";
		
		$html.="<div class='g-btn-edit active g-m-r g-fr order-status-btn' data-action='shouhuo'>确认收货</div>";
	}
	return $html;
	
}

//代理端 取消現金餘額提現申請
function __cashout_status_btns($status,$indetailpage=false){
	$html = "";
	if($status == 1){
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='quxiao'>取消申请</div>";
	}else if($status == 4){
		
	}
	return $html;
	
}



//零售客户获取自己的订单状态
function __order_status2($key,$withspan=false){
	$arr = \think\Config::get('nawen.order_status2');
	if(array_key_exists($key,$arr)){
		if($withspan){
			return "<span style='color:{$arr[$key][1]}'>{$arr[$key][0]}</span>";
		}else{
			return $arr[$key][0];
		}
	}else{
		return "";
	}
}
//零售小店 客户看自己的订单 根据订单状态显示对应操作按钮
function __order_status_btns_2($status,$indetailpage=false){
	
	$html = "";
	
	if($status == 1){
		//未支付
		$html.="<div class='g-btn-edit active g-m-r g-fr order-status-btn' data-action='zhifu'>立即支付</div>";
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='quxiao'>取消订单</div>";//single
		
	}else if($status == 2){
		//待审核
		//if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看打款凭证</div>";
		//}

	}else if($status == 3){
		//待发货
		
		//查看打款凭证
		//if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看打款凭证</div>";
		//}
	}else if($status == 4){
		//待收货
		if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='wuliu'>查看物流信息</div>";
		}
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看打款凭证</div>";
		
		$html.="<div class='g-btn-edit active g-m-r g-fr order-status-btn' data-action='shouhuo'>确认收货</div>";
	}else if($status == 5){
		//已收货
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看打款凭证</div>";
	}
	return $html;
}


//代理查看下级订单状态
function __order_status3($key,$ordertype=-1,$withspan=false){
	$arr = \think\Config::get('nawen.order_status3');
	if($key == 3){
		//子状态
		$arr = $arr[$key];
		$key = $ordertype;
	}
	if(array_key_exists($key,$arr)){
		if($withspan){
			return "<span style='color:{$arr[$key][1]}'>{$arr[$key][0]}</span>";
		}else{
			return $arr[$key][0];
		}
	}else{
		return '';
	}
}
//代理查看下级订单按钮
function __order_status_btns_3($status,$substatus=-1,$indetailpage=false){
	$html = "";
	if($status == 1){
		/*
		$html.="<div class='g-btn-edit active g-m-r g-fr order-status-btn' data-action='setpayed'>已付款</div>";
		*/
	}else if($status == 2){
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>打款审核</div>";
	}else if($status == 3){
		if($substatus == 1){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='daifa'>提货转发</div>";
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='zijifa'>线下发货</div>";
		}else if($substatus == 2){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看凭证</div>";
		}
	}else if($status == 4){
		if($indetailpage){
			$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='wuliu'>查看物流信息</div>";
		}
		$html.="<div class='g-btn-edit active g-m-r g-fr order-status-btn' data-action='shouhuo'>确认收货</div>";
	}else if($status == 6){
		//转发待审核
	}
	return $html;
}


//下级充值审核状态
function __agent_suborder_status($key,$ordertype=-1,$withspan=false){
	$arr = \think\Config::get('nawen.suborder_status');
	if(array_key_exists($key,$arr)){
		if($withspan){
			return "<span style='color:{$arr[$key][1]}'>{$arr[$key][0]}</span>";
		}else{
			return $arr[$key][0];
		}
	}else{
		return '';
	}
}
//下级充值订单按钮
function __suborder_status_btn($status,$substatus=-1,$indetailpage=false){
	/*
	'1' => ['待审核','#333'],
	'2' => ['已充值','#333'],
	'3' => ['已失效','#333'],
	*/
	$html = "";
	if($status == 1){
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看凭证</div>";
	}else if($status == 2){
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看凭证</div>";
	}else if($status == 3){
		$html.="<div class='g-btn-edit g-m-r g-fr order-status-btn' data-action='pinzheng'>查看凭证</div>";
	}
	return $html;
}

//下级代理升级状态对应按钮
function __subupgrade_status_btn($status,$indetailpage=false){
	/*
	0：可升级
	1：待资料审核（上级或者总部）
	2: 申请等级审核（上级或者总部）
	3：资料审核完成，待付货款
	4：已付货款，待审核（如不需要付货款，跳转到6）
	5：已付货款，审核失败
	6：货款审核完成，待付保证金（如果不需要增加保证金，跳9）
	7：已付保证金，待审核
	8：已付保证金，审核失败
	9：升级完成（更新等级，更新进货上级）
	-1：升级驳回/取消升级
	*/
	$html = "";
	if($status == 1){
		$html.="<a class='g-btn-edit g-m-r g-fr subupgrade-status-btn' data-action='sfsh'>身份审核</a>";
		$html.="<a class='g-btn-edit g-m-r g-fr subupgrade-status-btn' data-action='tiaojian'>升级条件</a>";
	}else if($status == 2){
		$html.="<a class='g-btn-edit g-m-r g-fr subupgrade-status-btn' data-action='dengjishenhe'>等级审核</a>";
		$html.="<a class='g-btn-edit g-m-r g-fr subupgrade-status-btn' data-action='tiaojian'>升级条件</a>";
	}else if($status == 3){
		
	}
	return $html;
}

//奖励提现列表的状态对应按钮
function __jiangli_status_btn($status,$indetailpage=false){
	/*
	奖励提取：
	status=5  取消申请
	status=6  打款凭证、未收到奖励、已收到奖励
	*/
	$html = "";
	if($status == 5){
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn active" data-action="quxiao">取消申请</div></div>';
	}else if($status == 6){
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn active" data-action="yishoudao">已收到奖励</div></div>';
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn" data-action="weishoudao">未收到奖励</div></div>';
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn" data-action="pinzheng">打款凭证</div></div>';
	}
	return $html;
}
//奖励支出列表的状态对应按钮
function __jiangli2_status_btn($status,$indetailpage=false){
	/*
	奖励提取：
	status=5  拒绝提款、去销账
	status=6  打款凭证
	*/
	$html = "";
	if($status == 5){
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn active" data-action="jujue">拒绝提款</div></div>';
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn active" data-action="xiaozhang">去销账</div></div>';
	}else if($status == 6){
		$html.='<div class="g-pd"><div class="g-btn-edit order-status-btn" data-action="pinzheng">打款凭证</div></div>';
	}
	return $html;
}





